package jp.sourceforge.talisman.mds.distance;

/*
 * $Id: CityBlockItemDistanceCalculator.java,v 1.1 2009/09/12 05:06:08 weiwei Exp $
 */

/**
 * City block (manhattan) metric calculator.
 * 
 * @author Haruaki Tamada
 * @version $Revision: 1.1 $ 
 */
public class CityBlockItemDistanceCalculator extends AbstractItemDistanceCalculator{

    @Override
    public ItemDistanceAlgorithm getAlgorithm(){
        return ItemDistanceAlgorithm.CITY_BLOCK_DISTANCE;
    }

    @Override
    public double calculate(double[] x, double[] y){
        validateArguments(x, y);
        double value = 0d;
        for(int i = 0; i < x.length; i++){
            if(!Double.isNaN(x[i]) && !Double.isNaN(y[i])){
                value += Math.abs(x[i] - y[i]);
            }
        }

        return value;
    }
}
